package cn.cvs.controller;

import cn.cvs.pojo.SysUser;
import cn.cvs.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController_html {
    @Resource
    UserService userService;
    @RequestMapping({"/user/list.html","/user/list"})
    public String userList(Model model){
        model.addAttribute("userlist",userService.findAll());
        return "userlist";
    }

    @RequestMapping({"/role/list.html","/role/list"})
    public String roleList(){
        return "rolelist";
    }

    @RequestMapping("/logout.html")
    public String logout(HttpServletRequest request){
        request.getSession().removeAttribute("currUser");
        return "redirect:/login.html";
    }
    @RequestMapping({"/user/add.html","/user/add"})
    public String userAdd(){
        return "adduser";
    }


    @RequestMapping({"/user/doAddUser.html","/user/doAddUser"})
    public String doAddUser(SysUser user){
        System.out.println(">>>>>>>>>>>adduser: "+user);
        //userService.addUser(user);
        return "redirect:/user/list.html";
    }


    @ResponseBody
   // @RequestMapping({"/user/view.html","/user/view"})
    // public String viewUser(@RequestParam String usrId){
    @RequestMapping({"/user/view.html/{usrId}","/user/view"})
    public String viewUser(@PathVariable String usrId){
        System.out.println(">>>>>>>>usrId: "+ usrId);
        return "usrId"+usrId;
    }

    @RequestMapping({"/main"})
    public String main(){
        return "fragment/main";
    }

    @RequestMapping({"/findex"})
    public String findex(){
        return "fragment/findex";
    }

    @RequestMapping({"/ulist"})
    public String ulist(){
        return "fragment/ulist";
    }
}
